//
//  ListViewController.m
//  HuateVideo
//
//  Created by Tiger on 12-5-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ListViewController.h"
#import "DetailViewController.h"
#import "CommonWebServices.h"
#import "Movie.h"
#import "DataList.h"
#import "Cache.h"
#import "CacheManager.h"
#import "SearchViewController.h"
@interface ListViewController ()
-(void)initTopView;
-(void)loadData;
-(void)loadFilterOption;
- (void)initFilter;
@end

@implementation ListViewController
@synthesize   detailType;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
		//        typeArray=[[NSMutableArray alloc] initWithObjects:LS(@"全部"),LS(@"动作"),LS(@"惊悚"),LS(@"伦理"),LS(@"战争"),LS(@"喜剧"),LS(@"爱情"), nil];
		//        areaArray=[[NSMutableArray alloc] initWithObjects:LS(@"全部"),LS(@"大陆"),LS(@"香港"),LS(@"日本"),LS(@"韩国"),LS(@"台湾"),LS(@"欧美"),LS(@"其他"), nil];
		//        yearArray=[[NSMutableArray alloc] initWithObjects:LS(@"全部"),LS(@"2012"),LS(@"2011"),LS(@"2010"),LS(@"2009"),LS(@"2008"),LS(@"2007"),LS(@"2006"),LS(@"2005"),LS(@"2004"),LS(@"2003"), nil];
        downloaderArray=[[NSMutableArray alloc] init];
		[self initFilter];
    }
    return self;
}

- (void)dealloc
{
	[parma release];
    [downloaderArray release];
	[typeArray release];
	[yearArray release];
	[areaArray release];
    [table release];
    [array release];
    [requestArray release];
    [super dealloc];
}
- (void)initFilter{
	typeFilter=@"全部";
	areaFilter=@"全部";
	yearFilter=@"全部";
	
}
- (NSArray*)bundleArrayWithName:(NSString*)bundleName{
	NSString* filePath=[[NSBundle mainBundle] pathForResource:bundleName ofType:@"plist"];
	NSArray* arrar=[NSArray arrayWithContentsOfFile:filePath];
	return arrar;
}
- (void)loadFilterOption{
	parma=[[NSMutableDictionary alloc] init];
	[parma setValue:@"0" forKey:@"Num"];
	[parma setValue:@"20" forKey:@"PageSize"];
    [parma setValue:@"1" forKey:@"PageNow"];
	areaArray=[[NSMutableArray alloc] init];
	typeArray=[[NSMutableArray alloc] init];
	yearArray=[[NSMutableArray alloc] init];
	
	switch (detailType) {
		case MovieChannelTypeMovie:
			[yearArray addObjectsFromArray:[self bundleArrayWithName:@"YearFilter"]];
			[areaArray addObjectsFromArray:[self bundleArrayWithName:@"Area"]];
			[typeArray addObjectsFromArray:[self bundleArrayWithName:@"MovieType"]];
			break;
		case MovieChannelTypeSeries:
			[yearArray addObjectsFromArray:[self bundleArrayWithName:@"YearFilter"]];
			[areaArray addObjectsFromArray:[self bundleArrayWithName:@"Area"]];
			[typeArray addObjectsFromArray:[self bundleArrayWithName:@"DeleType"]];
			break;
		case MovieChannelTypeMusic:
			[yearArray addObjectsFromArray:[self bundleArrayWithName:@"YearFilter"]];
			[areaArray addObjectsFromArray:[self bundleArrayWithName:@"Area"]];
			[typeArray addObjectsFromArray:[self bundleArrayWithName:@"MusicType"]];
			break;
		case MovieChannelTypeNews:
			[yearArray addObjectsFromArray:[self bundleArrayWithName:@"DateFilter"]];
			[typeArray addObjectsFromArray:[self bundleArrayWithName:@"NewsType"]];
			break;
		case MovieChannelTypeOriginal:
			[yearArray addObjectsFromArray:[self bundleArrayWithName:@"DateFilter"]];
			[typeArray addObjectsFromArray:[self bundleArrayWithName:@"OrigaType"]];
			break;
		case MovieChannelTypeMicroViedo:
			[yearArray addObjectsFromArray:[self bundleArrayWithName:@"DateFilter"]];
			[typeArray addObjectsFromArray:[self bundleArrayWithName:@"MicroType"]];
			break;
		default:
			break;
	}
	
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (downloaderArray.count) {
        [downloaderArray makeObjectsPerformSelector:@selector(cancelDownload)];
    }
    [requestArray makeObjectsPerformSelector:@selector(cancelRequest)];
}

-(void)pushSearchView{
    SearchViewController *searchViewController = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchViewController animated:YES];
    [searchViewController release];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    requestArray = [[NSMutableArray alloc]init];
    
    UIButton *searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame=CGRectMake(0, 0, 42, 31);
    [searchBtn setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(pushSearchView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* searchBarItem=[[UIBarButtonItem alloc] initWithCustomView:searchBtn];    
    self.navigationItem.rightBarButtonItem=searchBarItem;
    [searchBarItem release];
    
    CGRect tableFrame;
    self.view.backgroundColor = TOOLBAR_TINTCOLOR;
    if (self.detailType==MovieChannelTypeNews) {
        tableFrame=CGRectMake(0, 0, 320, 460-44-49);
        UIBarButtonItem*cate=[[UIBarButtonItem alloc] initWithTitle:LS(@"筛选") style:UIBarButtonItemStylePlain target:self action:@selector(toShuaixian)];
        self.navigationItem.rightBarButtonItem=cate;
        [cate release];
    }else {
        [self initTopView];
        tableFrame=CGRectMake(0, 40, 320, 327);
    }
    
    
    array = [[NSMutableArray alloc]init];
    [self loadFilterOption];
    
    table = [[UITableView alloc]initWithFrame:tableFrame];
    table.dataSource = self;
    table.delegate = self;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    table.backgroundColor = [UIColor clearColor];
    [self.view addSubview:table];
    
    [self loadData];
}

- (void)loadData
{
	[self.view showProgressText:YES];
    if (detailType == MovieChannelTypeMovie) {
        filterAction = @"GetMovideoScreen";
        filterRootXML = @"GetMovideoScreenResult";
    }
    else if (detailType == MovieChannelTypeSeries) {
        filterAction = @"GetDelePlayScreen";
        filterRootXML = @"GetDelePlayScreenResult";
    }
    else if (detailType == MovieChannelTypeMicroViedo) {
        filterAction = @"GetVideoScreen";
        filterRootXML = @"GetVideoScreenResult";
    }else if (detailType==MovieChannelTypeMusic) {
        filterAction = @"GetMusicScreen";
        filterRootXML = @"GetMusicScreenResult";
    }else if (detailType==MovieChannelTypeNews) {
        filterAction = @"GetMessageByScreenType";
        filterRootXML = @"GetMessageByScreenTypeResult";
    }else if (detailType==MovieChannelTypeOriginal) {
        filterAction = @"GetOriginalScreen";
        filterRootXML = @"GetOriginalScreenResult";
    }
	[parma setValue:yearFilter forKey:@"year"];

	if ([yearFilter isEqualToString:@"90年代"]) {
		[parma setValue:@"1" forKey:@"year"];
	}
	if ([yearFilter isEqualToString:@"80年代"]) {
		[parma setValue:@"2" forKey:@"year"];
	}
	if ([yearFilter isEqualToString:@"更早"]) {
		[parma setValue:@"3" forKey:@"year"];
	}
	
	
	
    [parma setValue:areaFilter forKey:@"area"];
    [parma setValue:typeFilter forKey:@"type"];
    CommonWebServices *webServ = [[CommonWebServices alloc] init];
    webServ.delegate = self;
    [requestArray addObject:webServ];
    [webServ startRequestWithMode:@"Default" Action:filterAction Parma:parma Class:@"DataList" RootXML:filterRootXML resultIsArray:YES];
    [webServ release];
	
//    CommonWebServices *webServ = [[CommonWebServices alloc] init];
//    webServ.delegate = self;
//    NSMutableDictionary *parma = [NSMutableDictionary dictionary];
//    [parma setValue:@"0" forKey:@"Num"];
//    [parma setValue:@"20" forKey:@"PageSize"];
//    [parma setValue:@"1" forKey:@"PageNow"];
//    [webServ startRequestWithMode:@"Default" Action:action Parma:parma Class:@"DataList" RootXML:rootXML resultIsArray:YES];
//    [webServ release];
}

#pragma mark - CommonWebServicesDelegate

- (void)onCommonWebServicesWithCustomClass:(id)object {
    if (object) {
        NSArray *movieList = ((DataList *)object).List;
        if (movieList.count) {
            [array removeAllObjects];
        }
        if ([movieList count]>0) {
            [array addObjectsFromArray:movieList];
            [table reloadData];
            [table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }
    }
    
    [self.view showProgressText:NO];
}

- (void)onCommonWebServicesFaild
{
    [self.view showProgressText:NO];
    
    UIAlertView	*alertview = [[UIAlertView alloc] initWithTitle:LS(@"加载失败")  
                                                        message:LS(@"请检查网络连接和设置")
                                                       delegate:self 	
                                              cancelButtonTitle:LS(@"确定")
                                              otherButtonTitles:nil];		
    [alertview show];		
    [alertview release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)initTopView
{
    UISegmentedControl *segmentControl ;
   // if (detailType!=MovieChannelTypeMicroViedo&&detailType!=MovieChannelTypeOriginal) {
//        NSString* f=LS(@"上映时间");
//        if (detailType==MovieChannelTypeMusic) {
//            f=LS(@"发行时间");
//        }
//        segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:f,LS(@"更新时间"),LS(@"播放次数"),nil]];
//    }else {
//        segmentControl=[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:LS(@"更新时间"),LS(@"播放次数"),nil]];
//    }
	if (detailType!=MovieChannelTypeMusic) {
		segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:LS(@"最新视频"),LS(@"热播排行"),LS(@"推荐视频"),nil]];

	}else {
		segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:LS(@"最近发行"),LS(@"热播排行"),LS(@"推荐音乐"),nil]];
	}

    
    if (LOCALSWITCH == 1) {
        UILabel *paixu = [[UILabel alloc]initWithFrame:CGRectMake(10, 7, 50, 26)];
        paixu.text = [NSString stringWithFormat:@"%@:",LS(@"排序")];
        paixu.textColor = [UIColor whiteColor];
        paixu.backgroundColor = [UIColor clearColor];
        paixu.font = [UIFont systemFontOfSize:12.0];
        [self.view addSubview:paixu];
        [paixu release];
        
        segmentControl.frame = CGRectMake(40, 7, 195, 26);
    }
    else {
        segmentControl.frame = CGRectMake(10, 7, 225, 26);
    }
    
    segmentControl.tintColor = TOOLBAR_TINTCOLOR;
	[segmentControl setSegmentedControlStyle:UISegmentedControlStyleBar];
	[segmentControl setSelectedSegmentIndex:0];
	[segmentControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
	[self.view addSubview:segmentControl];
	[segmentControl release];
    
    UIButton *bendi = [[UIButton alloc]initWithFrame:CGRectMake(255, 7, 55, 26)];
    [bendi setBackgroundImage:[UIImage imageNamed:@"liangzianniu.png"] forState:UIControlStateNormal];
    [bendi setTitle:LS(@"筛选") forState:UIControlStateNormal];
    [bendi addTarget:self action:@selector(toShuaixian) forControlEvents:UIControlEventTouchUpInside];
    bendi.titleLabel.font = [UIFont systemFontOfSize:12.0];
    [self.view addSubview:bendi];
    [bendi release];
    
    UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(0, 39, 320, 2)];
    line.image = [UIImage imageNamed:@"fengexian.png"];
    [self.view addSubview:line];
    [line release];
}

- (void)toShuaixian
{
    if (_actionSheet==nil) {
        _actionSheet = [[UIActionSheet alloc]initWithTitle:nil 
                                                  delegate:nil
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];
        _actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        UISegmentedControl *closeButton = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObject:@"取消"]];
        closeButton.momentary = YES;
        closeButton.tag=1;
        closeButton.frame = CGRectMake(10, 7, 50, 30);
        closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
        closeButton.tintColor = [UIColor blackColor];
        [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
        [_actionSheet addSubview:closeButton];
        [closeButton release];
        
        UILabel*year=[[UILabel alloc] initWithFrame:CGRectMake(10, 40, 100, 30)];
        year.text=LS(@"时间");
        year.textAlignment=UITextAlignmentCenter;
        year.textColor=[UIColor whiteColor];
        year.backgroundColor=[UIColor clearColor];
        [_actionSheet addSubview:year];
        [year release];
        
        UILabel*type=[[UILabel alloc] initWithFrame:CGRectMake(110, 40, 100, 30)];
        type.text=LS(@"类型");
        type.textAlignment=UITextAlignmentCenter;
        type.textColor=[UIColor whiteColor];
        type.backgroundColor=[UIColor clearColor];
        [_actionSheet addSubview:type];
        [type release];
        
        UILabel*area=[[UILabel alloc] initWithFrame:CGRectMake(210, 40, 100, 30)];
        area.text=LS(@"地区");
        area.textAlignment=UITextAlignmentCenter;
        area.textColor=[UIColor whiteColor];
        area.backgroundColor=[UIColor clearColor];
        [_actionSheet addSubview:area];
        [area release];
        if (detailType==MovieChannelTypeOriginal||detailType==MovieChannelTypeMicroViedo||detailType==MovieChannelTypeNews) {
            area.hidden=YES;
            year.frame=CGRectMake(10, 40, 150, 30);
            type.frame=CGRectMake(150, 40, 150, 30);
        } 
        UISegmentedControl *doneButton = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObject:@"确定"]];
        doneButton.momentary = YES;
        doneButton.tag=1;
        doneButton.frame = CGRectMake(260, 7, 50, 30);
        doneButton.segmentedControlStyle = UISegmentedControlStyleBar;
        doneButton.tintColor = [UIColor blackColor];
        [doneButton addTarget:self action:@selector(doActionSheet:) forControlEvents:UIControlEventValueChanged];
        [_actionSheet addSubview:doneButton];
        [doneButton release];
        
    }
    if (_pickerView==nil) {
        _pickerView = [[UIPickerView alloc]initWithFrame:CGRectZero];
        _pickerView.frame = CGRectMake(0, 70, 320, 216);
        _pickerView.showsSelectionIndicator = YES;
        _pickerView.delegate = self;
        _pickerView.dataSource=self;
        [_actionSheet addSubview:_pickerView];
    }
    [_actionSheet showFromRect:CGRectMake(0, 0, 320, 260) inView:self.view animated:YES];
    [_actionSheet setBounds:CGRectMake(0, 0, 320, 585)];
}

-(void)dismissActionSheet:(id)sender{
	if (![yearFilter isEqualToString:[parma valueForKey:@"year"]]) {
		yearFilter=[parma valueForKey:@"year"];
		int index0=[yearArray indexOfObject:yearFilter];
		[_pickerView selectRow:index0 inComponent:0 animated:NO];
	}
	if (![typeFilter isEqualToString:[parma valueForKey:@"type"]]) {
		typeFilter=[parma valueForKey:@"type"];
		int index1=[typeArray indexOfObject:typeFilter];
		[_pickerView selectRow:index1 inComponent:1 animated:NO];
	}
	if (![areaFilter isEqualToString:[parma valueForKey:@"area"]]) {
		areaFilter=[parma valueForKey:@"year"];
		int index2=[areaArray indexOfObject:areaFilter];
		[_pickerView selectRow:index2 inComponent:2 animated:NO];
	}
    [_actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    
}

-(void)doActionSheet:(id)sender{
    [_actionSheet dismissWithClickedButtonIndex:0 animated:YES];
	 [self loadData];
  }
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    if (detailType==MovieChannelTypeOriginal||detailType==MovieChannelTypeMicroViedo||detailType==MovieChannelTypeNews) {
        return 2;
    }
    return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (detailType==MovieChannelTypeOriginal||detailType==MovieChannelTypeMicroViedo||detailType==MovieChannelTypeNews) {
        if (component==0) {
            return yearArray.count;
        }else {
            return typeArray.count;
        }
    }else {
        if (component==0) {
            return yearArray.count;
        }else if(component==1){
            return typeArray.count;
        }else {
            return areaArray.count;
        }
    }
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component==0) {
        return LS([yearArray objectAtIndex:row]);
    }
    else if (component==1) {
        return LS([typeArray objectAtIndex:row]);
    }else {
        return LS([areaArray objectAtIndex:row]);
    }
    
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    switch (component) {
        case 0:
            yearFilter=[yearArray objectAtIndex:row];
            NSLog(@"%@",yearArray);
            NSLog(@"%@",yearFilter);
            break;
        case 1:
            typeFilter=[typeArray objectAtIndex:row];
            NSLog(@"%@",typeArray);
            NSLog(@"%@",typeFilter);
            break;
        case 2:
            areaFilter=[areaArray objectAtIndex:row];
            NSLog(@"%@",areaArray);
            NSLog(@"%@",areaFilter);
            break;            
        default:
            break;
    }
}

- (void)segmentChanged:(id)sender
{
	
    switch (((UISegmentedControl *)sender).selectedSegmentIndex) {
        case 0:
            [parma setValue:@"0" forKey:@"Num"];
            break;
        case 1:
            [parma setValue:@"1" forKey:@"Num"];
            break;
        case 2:
            [parma setValue:@"2" forKey:@"Num"];
            break;
        default:
            break;
    }
	[self initFilter];

	[self loadData];
//    CommonWebServices *webServ = [[CommonWebServices alloc] init];
//    webServ.delegate = self;
//    [webServ startRequestWithMode:@"Default" Action:action Parma:parma Class:@"DataList" RootXML:rootXML resultIsArray:YES];
//    [webServ release];
//    [self.view showProgressText:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 115;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [array count];
}

- (void)downImg:(NSDictionary*)dic {
	id movie=[dic valueForKey:@"item"];
	int tag=[[dic valueForKey:@"rowNum"] row];
	ImageDownloader* downloader=[[ImageDownloader alloc] init];
	downloader.imageURL=[movie News_pic];
	downloader.delegate=self;
	downloader.tag=tag;
	[downloader startDownload:YES];
	[downloaderArray addObject:downloader];
	[downloader release];
	
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	
	static NSString* ListIdentifier = @"ListIdentifier";
	UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:ListIdentifier];
	
	if (cell == nil)
	{
		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ListIdentifier];
		//cell.selectionStyle = UITableViewCellSelectionStyleNone;  //去掉选中时的颜色
	}
	
	for (UIView* subView in [cell.contentView subviews])
	{
		[subView removeFromSuperview];
	}
    
	if (indexPath.row < [array count]) {
        
        id movie = [array objectAtIndex:indexPath.row];
		
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 75, 95)];
        image.tag=1000;
        [cell.contentView addSubview:image];
        [image release];
        NSString*imgurl=[movie News_pic];
        NSLog(@"%@=========\n%@",[movie News_title],imgurl);
        if ((![imgurl isEqual:[NSNull null]])&&imgurl.length>0) {
//            Cache* cache=[CacheManager queryCacheWithCacheKey:imgurl];
            UIImage*tImg=[movie iconImg];
			if (tImg) {
//                NSData *data = [NSData dataWithContentsOfFile: cache.cobject];
//                image.image = [UIImage imageWithData: data];
				image.image=[movie iconImg];
            }else {
                image.image = [UIImage imageNamed:@"dengdai.png"];
				NSDictionary* dic=[NSDictionary dictionaryWithObjectsAndKeys:movie,@"item",indexPath,@"rowNum",nil];
				[self performSelector:@selector(downImg:) withObject:dic afterDelay:0.2];
            }
        }
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(95, 10, 200, 20)];
        label.text = [movie News_title];
        label.textColor = LIGHT_COLOR;
        label.font = [UIFont systemFontOfSize:16.0];
        label.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:label];
        [label release];
		
        label = [[UILabel alloc]initWithFrame:CGRectMake(95, 35, 200, 20)];
        label.text = [NSString stringWithFormat:@"%@: %@",LS(@"导演"),[movie News_arg3]];
        label.textColor = [UIColor lightGrayColor];
        label.font = [UIFont systemFontOfSize:14.0];
        label.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:label];
        [label release];
        if (detailType==MovieChannelTypeNews) {
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"发布时间"),[movie News_pub_time]];
        }
        if (detailType==MovieChannelTypeMicroViedo) {
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"上传者"),[movie News_author]];
        }
        if (detailType==MovieChannelTypeOriginal) {
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"拍摄时间"),[movie News_arg5]];
        }
        if (detailType==MovieChannelTypeMusic) {
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"歌手"),[movie News_author]];
        }
        label = [[UILabel alloc]initWithFrame:CGRectMake(95, 60, 200, 20)];
        label.text = [NSString stringWithFormat:@"%@: %@",LS(@"主演"),[movie News_arg2]];
        label.textColor = [UIColor lightGrayColor];
        label.font = [UIFont systemFontOfSize:14.0];
        label.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:label];
        [label release];
        
        if (detailType==MovieChannelTypeNews) {
            label.frame=CGRectMake(95, 60, 200, 40);
            label.numberOfLines=0;
//            label.text=@"乌鲁木齐6月开始进行田字工程施工，届时所有车辆需绕道行驶...";
        }
        if (detailType==MovieChannelTypeMicroViedo) {
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"上传时间"),[movie News_arg5]];
        }
        if (detailType==MovieChannelTypeMusic) {
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"专辑"),[movie News_arg1]];
        }
        if (detailType==MovieChannelTypeOriginal||detailType==MovieChannelTypeNews) {
            NSString*content=[movie News_content];
            if (content) {
                CFShow(content);
            }
            label.text=[NSString stringWithFormat:@"%@: %@",LS(@"摘要简介"),content];
        }
        if (detailType!=MovieChannelTypeMusic&&detailType!=MovieChannelTypeNews){
            label = [[UILabel alloc]initWithFrame:CGRectMake(95, 85, 200, 20)];
            label.text = [NSString stringWithFormat:@"%@: %d%@",LS(@"总播放"),[movie News_click_count],LS(@"次")];
            label.textColor = [UIColor lightGrayColor];
            label.font = [UIFont systemFontOfSize:14.0];
            label.backgroundColor = [UIColor clearColor];
            [cell.contentView addSubview:label];
            [label release];
        }
        
        UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(0, 114, 320, 2)];
        line.image = [UIImage imageNamed:@"fengexian.png"];
        [cell.contentView addSubview:line];
        [line release];
    }
	
	cell.backgroundColor = [UIColor clearColor];
	
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row < [array count]) {
        DetailViewController *detailViewController = [[DetailViewController alloc]init];
        detailViewController.movie = [array objectAtIndex:indexPath.row];
        detailViewController.type = 2;
        detailViewController.channelType = detailType;
        [self.navigationController pushViewController:detailViewController animated:YES];
        [detailViewController release];
    }
}
#pragma mark imagedownloaderDelegate
- (void)appImageDidLoad:(UIImage *)image withTag:(int)tag{
    NSLog(@"load ++++++++%d",tag);
	id t_movie=[array objectAtIndex:tag];
    UITableViewCell* cell=[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:tag inSection:0]];
    UIImageView* img=(UIImageView*)[cell.contentView viewWithTag:1000];
    if (image) {
		[t_movie setIconImg:image];
        img.image=image;
    }
}
@end
